home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / what20.zip / WHAT.C < prev    next >
C/C++ Source or Header  |  1988-08-14  |  2KB  |  70 lines

  1. /*
  2.  * what.c: version 2.0 88-8-14 Copyright 1988 R. T. Coates
  3.  *******************************************************************************
  4.  * INVOCATION:
  5.  *
  6.  *   what file [file file ...]
  7.  *******************************************************************************
  8.  * DESCRIPTION:
  9.  *
  10.  * looks for the string @(#) in files and prints the characters following
  11.  * the key string until newline, null, double quote, greater than, or
  12.  * back slash (\n, \0, ", >, \) is found.
  13.  *******************************************************************************
  14.  */
  15.  
  16. static char *PROGID =
  17. "@(#) what.c 2.0 88-8-14 Copyright 1987 R. T. Coates";
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21.  
  22. main(int argc,char **argv)
  23. {
  24.     FILE *fp;
  25.     register int c,sv;
  26.  
  27.     if(argc < 2) {            /* wrong number of parameters */
  28.         fprintf(stderr,"usage: %s file file ...\n",argv[0]);
  29.         exit(1); }
  30.  
  31.     while(--argc) {            /* do all files */
  32.         if((fp = fopen(*++argv,"rb")) == NULL) {
  33.             fprintf(stderr,"warning: %s: %s\n", *argv,sys_errlist[errno]);
  34.             continue; }
  35.  
  36.     printf("%s: \n\t",*argv);    /* print file name */
  37.         sv = 0;                /* init to state 0 */
  38.  
  39.         while((c = getc(fp)) != EOF) {
  40.             if(sv == 4) {        /* found entire key string */
  41.         /* look for terminating character */
  42.                 if ((char)c == '\0' || (char)c == '\n' ||
  43.                   (char)c == '"' || (char)c == '>' ||
  44.                   (char)c == '\\') {
  45.             sv = 0;            /* termination found */
  46.                     putchar('\n');
  47.                     putchar('\t');
  48.                     continue; }            /* keep on looking for key */
  49.                 putchar((char) c);
  50.                 continue; }
  51.             if((char)c == '@' && sv == 0) {    /* found first char: @ */
  52.                 sv = 1;
  53.                 continue; }
  54.             if((char)c == '(' && sv == 1) {    /* found second char: ( */
  55.                 sv = 2;
  56.                 continue; }
  57.             if((char)c == '#' && sv == 2) {    /* found third char: # */
  58.                 sv = 3;
  59.                 continue; }
  60.             if((char)c == ')' && sv == 3) {    /* found fourth char: ) */
  61.                 sv = 4;
  62.                 continue; }
  63.             sv = 0; }
  64.     printf("\n");
  65.     fclose(fp); }
  66.     printf("\n");
  67. }
  68.  
  69. /* end of what.c */
  70.